package shiqi.constants;

import lombok.Getter;

@Getter
public enum DbEnum {

    USERDATASOURCE("userDataSource", "用列表存储的数据库") {
        @Override
        public void getFeatureInfo() {
            System.out.println("存储方便，占用空间比较小，遍历慢");
        }
    },
    MAPUSERDATASOURCE("mapUserDataSource", "用map存储数据的数据库") {
        @Override
        public void getFeatureInfo() {
            System.out.println("根据id获取会比较快，空间换时间");
        }
    };

    private final String name;
    private final String desc;

    DbEnum(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    // 可以定义抽象方法交子类实现
    protected abstract void getFeatureInfo();

    public static void printFeatureInfo(String name) {
        getDbEnumByName(name).getFeatureInfo();
    }

    public static DbEnum getDbEnumByName(String name) {
        DbEnum[] values = DbEnum.values();
        for (DbEnum dbEnum: values) {
            if (dbEnum.getName().equals(name)) {
                return dbEnum;
            }
        }
        throw new IllegalArgumentException("Invalid Enum name:" + name);
    }
}
